home *** CD-ROM | disk | FTP | other *** search
- #include <ConvertTools.h>
- #include <MathTools.h>
-
- /*=======================================================================*/
- /*= This file contains a set of utilities for converting text & strings =*/
- /*=======================================================================*/
-
- void CToPString (char *CStr, Str255 *PStr, short maxLen)
- /* convert maxLen characters of the the c string passed in CStr into a */
- /* pascal-syle string. PStr must already by allocated */
- {
- short len;
-
- if (PStr && *PStr && CStr)
- {
- len = Min (strlen(CStr), maxLen);
- BlockMove (CStr, &((*PStr)[1]), len);
- **PStr = len;
- }
- }
-
- /*------------------------------------------------------------------------------*/
-
- void PToCString (StringPtr PString, char *CStr, short maxLen)
- /* convert maxLen characters of the the pascal string passed in PStr into a */
- /* c-syle string. CStr must already by allocated */
- {
- short len;
-
- if (PString && CStr)
- {
- len = Min (maxLen, *PString);
- BlockMove (PString+1, CStr, len);
- CStr[len] = '\0';
- }
- }
-
- /*------------------------------------------------------------------------------*/
-
- StringPtr Data2PString (void *InData, short DataLen)
- /* copy the passed data into a new Pascal string */
- {
- Ptr NewPtr = NULL;
-
- if (InData)
- {
- NewPtr = NewPtrClear(DataLen+1);
- if (NewPtr)
- {
- BlockMove(InData, NewPtr+1, DataLen);
- NewPtr[0] = DataLen;
- return (StringPtr)NewPtr;
- }
- else
- return NULL;
- }
- else
- return NULL;
- }
-
- /*------------------------------------------------------------------------------*/
-
- Ptr Data2Ptr (void *InData, short DataLen)
- /* copy the passed data into a new pointer */
- {
- Ptr NewPtr = NULL;
-
- if (InData)
- {
- NewPtr = NewPtrClear(DataLen);
- if (NewPtr)
- {
- BlockMove(InData, NewPtr, DataLen);
- return NewPtr;
- }
- else
- return NULL;
- }
- else
- return NULL;
- }
-
- /*------------------------------------------------------------------------------*/
-
- Handle PString2Text (StringPtr TheString)
- /* make a copy of the string and store it in handle with no length byte */
- {
- Handle H = NULL;
-
- H = NewHandleClear(*TheString);
- if (H)
- BlockMove(TheString+1, *H, *TheString);
- return H;
- }
-
- /*------------------------------------------------------------------------------*/
-
- StringPtr Text2PString (Handle TheString)
- /* copy the text in the handle into a Pascal string */
- {
- long numBytes;
- StringPtr STemp = NULL;
-
- if (!TheString) return NULL;
-
- numBytes = GetHandleSize(TheString);
-
- if (TheString)
- {
- STemp = (StringPtr)NewPtrClear(numBytes+1);
- if (STemp)
- {
- BlockMove(*TheString, &(STemp[1]), numBytes);
- STemp[0] = (short)numBytes;
- }
- }
- return STemp;
- }
-
- /*------------------------------------------------------------------------------*/
-
-